package rsj.api.test;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.dao.TestLogDao;

/**
 * @author yuanqinglong
 * @since 2020/10/21 17:40
 */
@RestController
public class GetFileIdName extends BaseLink {

    private static final TestLogDao TEST_LOG_DAO = TestLogDao.getInstance();

    @Override
    @RequestMapping(value = "rsj_data_get_file_info")
    public Box executeLink(Box box) {
        MapNode data = box.getMapNode("data");
        String logId = data.getValue("log_id");
        MapNode info = TEST_LOG_DAO.getFileInfoByLogId(logId);
        if (info.size() == 0) {
            return BoxUtil.errorBox(box, "此记录不存在");
        }
        TableNode tableNode = new TableNode();
        MapNode mapNode = new MapNode();
        mapNode.putNode("file_id", info.getValue("Log_Res_Id"));
        mapNode.putNode("file_name", info.getValue("Log_Res_Name"));
        //MapNode mapNode1 = new MapNode();
        //mapNode1.putNode("file_id",info.getValue("Log_Par_Id"));
        //mapNode1.putNode("file_name",info.getValue("Log_Par_Name"));
        tableNode.putMap(mapNode);
        //tableNode.putMap(mapNode1);
        MapNode mapNode2 = new MapNode();
        mapNode2.putNode("__file_list__", tableNode.toJson());
        return BoxUtil.successBoxToData(box, "成功", mapNode2);
    }
}
